/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights
 * reserved. <a>http://www.cqcis.com</a>
 */
package com.cq.bd.dao.jdbc;

import java.util.List;

import com.cq.base.orm.jdbc.BaseJdbcDao;
import com.cq.base.orm.jdbc.JdbcUtil;
import com.cq.bd.domain.SFunction;

/**
 * 权限
 * 
 * @author huangmy
 * @date   2009-10-7
 */
public class SFunctionJdbcDao extends BaseJdbcDao {
    private static String rootFuncQuerySql = "select b.* from s_menu a, s_function b, " +
    		"s_function_reso c where a.menu_id=c.reso_id and c.reso_type=1 and a.state=1" +
    		" and b.func_id=c.func_id and b.state=1 and a.menu_up_id=?";
    
    private static String subFuncQuerySql = "select b.* from s_menu a, s_function b, " +
            "s_function_reso c,s_function_reso d where a.menu_id=c.reso_id and c.reso_type=1 and a.state=1" +
            " and b.func_id=c.func_id and b.state=1 and a.menu_up_id=d.reso_id and d.reso_type=1 " +
            " and c.func_id=?";
    
    /**
     * 权限
     * 
     * @param upperFuncId
     * @return
     */
    public List<SFunction> getSubFuncs(Long upperFuncId) {
        if (upperFuncId == -1) {
            return JdbcUtil.queryForList(this, SFunction.class, rootFuncQuerySql, 10000L);
        } else {
            return JdbcUtil.queryForList(this, SFunction.class, subFuncQuerySql, upperFuncId);
        }        
    }
}
